#!/usr/bin/env bash
target=8500_evb

#8500_evb
#8500_st239
#8500_demov1
#8500_8500f1
#8500_cultra

function flash()
{
    ctmake CT_RELEASE=debug CT_TARGET=${target} WITHOUT_WERROR=1 CT_OPT=dbg_size CT_USERGEN=no CT_PRODUCT=tv
}

function ramrun()
{
    cd toolpool/flash_programmer && ../../prjmake ${target} release && cd ../..
}

function clean()
{
    rm build/ -rf
    ctmake CT_RELEASE=debug CT_TARGET=${target} WITHOUT_WERROR=1 CT_OPT=dbg_size CT_USERGEN=no CT_PRODUCT=tv clean
}

function work()
{
    cd /home/wangxiaobin/projects
    source /opt/crosscompiler/cygenv.sh git
}

function help()
{
    echo "**********************************************************"
    echo -e "*    \e[1;31m  Usage describtion as following:\e[0m                   *"
    echo -e "*    \e[1;31m  -w: excute function work(),set enviroment              *"
    echo -e "*    \e[1;31m  -f: excute function flash(),generate flash.lod         *"
    echo -e "*    \e[1;31m  -r: excute function ramrun(),generate ramrun.lod       *"
    echo -e "*    \e[1;31m  -c: excute function clear(),clean ./build\e[0m         *"
    echo -e "*    \e[1;31m  -m: excute function move(),move hex to home\e[0m       *"
    echo -e "*    \e[1;31m  -h: excute function help(),usage describtion\e[0m      *"
    echo "**********************************************************"
}

function move()
{
    cp -r ./hex ~
}

function understand()
{
    cmd=$1
    if [ "$cmd" = "-w" ]; then
        echo '-------------work() begin---------------'
        work
    elif [ "$cmd" = "-f" ]; then
        echo '-------------flash() begin--------------'
        flash
    elif [ "$cmd" = "-r" ]; then
        echo '-------------ramrun() begin-------------'
        ramrun
    elif [ "$cmd" = "-c" ]; then
        echo '-------------clean() begin--------------'
        clean
    elif [ "$cmd" = "-m" ]; then
        echo '--------------move() begin--------------'
        move
    else
        help
    fi
}

for func in "$*"
do
    understand ${func}
done

date "+%Y-%m-%d %H:%M:%S" 
